package com.maimao.model.user;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.maimao.model.user.sys.Role;
import lombok.*;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 网站用户
 *
 * @author MaoLin Wang
 * @date 2020/11/28 11:08 上午
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName("mm_user")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class User implements Serializable {
    @TableId(type = IdType.ASSIGN_ID)
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long id;

    @TableField("username")
    private String username;

    @TableField("password")
    private String password;

    /**
     * 性别1男0女
     */
    @TableField("`gender`")
    private Integer gender;

    @TableField("`mobile`")
    private String mobile;

    @TableField("`email`")
    private String email;

    /**
     * 后期用于微信认证
     */
    @TableField("`wx_id`")
    private String wxId;

    @TableField("id_url_front")
    private String idUrlFront;

    @TableField("id_url_back")
    private String idUrlBack;

    @TableField("id_url_hand")
    private String idUrlHand;

    /**
     * 1正常0冻结
     */
    @TableField("`status`")
    private Integer status;

    @TableField("`birthday`")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonSerialize(using = LocalDateSerializer.class)
    private LocalDate birthday;

    /**
     * 0 未开店 1 正常开店 2 申请中 3 冻结中 4 关闭 5 审核未通过
     */
    @TableField("shop_status")
    private Integer shopStatus;

    @TableField("create_time")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;

    /**
     * 拥有积分
     */
    @TableField("integral")
    private Integer integral;

    /**
     * 冻结积分（下单未付款获得的积分不可使用）
     */
    @TableField("freeze_integral")
    private Integer freezeIntegral;

    @TableField(exist = false)
    private List<Role> roleList;

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", gender=" + gender +
                ", mobile='" + mobile + '\'' +
                ", email='" + email + '\'' +
                ", wxId='" + wxId + '\'' +
                ", idUrlFront='" + idUrlFront + '\'' +
                ", idUrlBack='" + idUrlBack + '\'' +
                ", idUrlHand='" + idUrlHand + '\'' +
                ", status=" + status +
                ", birthday=" + birthday +
                ", shopStatus=" + shopStatus +
                ", createTime=" + createTime +
                ", integral=" + integral +
                ", freezeIntegral=" + freezeIntegral +
                '}';
    }
}
